<?php
/**
 * Created by PhpStorm.
 * User: zyw
 * Date: 2018-04-09
 * Time: 10:50
 */

class Sys extends MY_Controller{

    public function __construct(){
        parent::__construct();
    }

    /**
     * 版本升级列表
     */
    public function version_list(){
        $pageTitle = "版本升级列表";
        $app_id = $this->input->get_post("app_id") ? $this->input->get_post("app_id") : 1;
        $page = $this->input->get_post("page") ? $this->input->get_post("page") : 1;
        $pagesize = $this->input->get_post("pagesize") ? $this->input->get_post("pagesize") : 20;
        $where = array("app_id" => $app_id,"status" => 1);
        $orderBy = array("version_code" => "desc");
        $vList = $this->VersionUpgrade->getList($where, $page, $pagesize, $orderBy);
        $num = $this->VersionUpgrade->getListNum($where);

        $url = "index.php?c=sys&m=version_list&app_id=".$app_id;
        $multipage = multipage($num, $page, $pagesize, $url);

        $this->load->view('sys/version_list',array(
            "pageTitle" => $pageTitle,
            "vList" => $vList,
            "multipage" => $multipage
        ));
    }

    /**
     * 添加 / 编辑 版本升级
     */
    public function version_set(){
        $pageTitle = "编辑";
        $id = $this->input->get_post("id");
        if($_REQUEST["submits"]){
            $param = $this->input->get_post("version");
            $param["version_code"] = $param["version_id"].".".intval($param["version_mini"]);
            $param["update_time"] = time();
            if(empty($id)){
                $param["add_time"] = time();
                $this->VersionUpgrade->insert_one($param);
            }else{
                $this->VersionUpgrade->update_data($param, array("id" => $id));
            }
            showMessage("index.php?c=sys&m=version_list&app_id=".$param["app_id"]);

        }
        $version = array();
        if(!empty($id)){
            $version = $this->VersionUpgrade->query_one(array("id" => $id));
        }
        $this->load->view('sys/version_set',array(
            "pageTitle" => $pageTitle,
            "version" => $version,
            "id" => $id
        ));
    }

    /**
     * 删除版本更新记录
     */
    public function version_del(){
        $id = $this->input->get_post("id");
        if(empty($id)){
            std_out(-1, "id不能为空");
        }
        $this->VersionUpgrade->del_data(array("id" => $id));

        std_out(0, "");
    }

    /**
     * 美化数据列表
     */
    public function post_beautify(){
        $pageTitle = "美化数据列表";

        $page = $this->input->get_post("page") ? $this->input->get_post("page") : 1;
        $pagesize = $this->input->get_post("pagesize") ? $this->input->get_post("pagesize") : 20;
        $where = array();
        $orderBy = array("add_time" => time());
        $pList = $this->PostBeautify->getList($where, $page, $pagesize, $orderBy);
        $num = $this->PostBeautify->getListNum($where);

        $url = "index.php?c=sys&m=post_beautify";
        $multipage = multipage($num, $page, $pagesize, $url);

        $this->load->view('sys/post_beautify',array(
            "pageTitle" => $pageTitle,
            "pList" => $pList,
            "multipage" => $multipage
        ));
    }

    /**
     * 添加 / 编辑美化数据规则
     */
    public function beautify_edit(){
        $pageTitle = "编辑";
        $id = $this->input->get_post("id");
        if($_REQUEST["submits"]){
            $param = $this->input->get_post("param");
            $param["add_time"] = time();
            if(empty($id)){
                $this->PostBeautify->insert_one($param);
            }else{
                $this->PostBeautify->update_data($param, array("id"=>$id));
            }
            showMessage("index.php?c=sys&m=post_beautify");
        }
        $beautify = array();
        if(!empty($id)){
            $beautify = $this->PostBeautify->query_one(array("id" => $id));
        }
        $this->load->view('sys/post_beautify_edit',array(
            "pageTitle" => $pageTitle,
            "beautify" => $beautify,
            "id" => $id
        ));
    }

    /**
     * 设置状态
     */
    public function beautify_status(){
        $id = $this->input->get_post("id");
        $status = $this->input->get_post("status");

        $param = array("status" => $status);
        $this->PostBeautify->update_data($param, array("id"=>$id));

        std_out(0, "");
    }



    /**
     * 美化数据列表
     */
    public function post_auto_beautify(){
        $pageTitle = "导入无评论帖子美化数据列表";

        $page = $this->input->get_post("page") ? $this->input->get_post("page") : 1;
        $pagesize = $this->input->get_post("pagesize") ? $this->input->get_post("pagesize") : 20;
        $where = array();
        $orderBy = array("start_time" => "ASC");
        $pList = $this->PostAutoBeautify->getList($where, $page, $pagesize, $orderBy);
        $num = $this->PostAutoBeautify->getListNum($where);

        $url = "index.php?c=sys&m=post_auto_beautify";
        $multipage = multipage($num, $page, $pagesize, $url);

        $this->load->view('sys/post_auto_beautify',array(
            "pageTitle" => $pageTitle,
            "pList" => $pList,
            "multipage" => $multipage
        ));
    }

    /**
     * 添加 / 编辑美化数据规则
     */
    public function beautify_auto_edit(){
        $pageTitle = "编辑";
        $id = $this->input->get_post("id");
        if($_REQUEST["submits"]){
            $param = $this->input->get_post("param");
            $param["add_time"] = time();
            if(empty($id)){
                $this->PostAutoBeautify->insert_one($param);
            }else{
                $this->PostAutoBeautify->update_data($param, array("id"=>$id));
            }
            showMessage("index.php?c=sys&m=post_auto_beautify");
        }
        $beautify = array();
        if(!empty($id)){
            $beautify = $this->PostAutoBeautify->query_one(array("id" => $id));
        }
        $this->load->view('sys/post_auto_beautify_edit',array(
            "pageTitle" => $pageTitle,
            "beautify" => $beautify,
            "id" => $id
        ));
    }

    /**
     * 设置状态
     */
    public function beautify_auto_status(){
        $id = $this->input->get_post("id");
        $status = $this->input->get_post("status");

        $param = array("status" => $status);
        $this->PostAutoBeautify->update_data($param, array("id"=>$id));

        std_out(0, "");
    }
}